package com.ruoyi.quartz.task;

import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.coupons.domain.Coupons;
import com.ruoyi.coupons.domain.CouponsMember;
import com.ruoyi.coupons.service.ICouponsMemberService;
import com.ruoyi.coupons.service.ICouponsService;
import com.ruoyi.shopping.domain.MallCoupons;
import com.ruoyi.shopping.domain.MallCouponsMember;
import com.ruoyi.shopping.service.IMallCouponsMemberService;
import com.ruoyi.shopping.service.IMallCouponsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author chengliang
 * @date 2022/3/3
 **/
@Component("couponTask")
public class CouponTask {

    @Autowired
    private ICouponsMemberService service;
    @Autowired
    private ICouponsService couponsService;
    @Autowired
    private IMallCouponsMemberService mallCouponsMemberService;
    @Autowired
    private IMallCouponsService mallCouponsService;
    //团购优惠券
    public void couponsOverdue(){
        List<CouponsMember> list = service.selectNeedOverdue();
        list.forEach(e->{
            e.setCanUseState(DicConstants.SYS_N.getCode());
            service.updateCouponsMember(e);
        });
    }
    public void couponsStoreOverdue(){
        List<Coupons> list = couponsService.selectNeedOverdue();
        list.forEach(e->{
            e.setState(DicConstants.SYS_N.getCode());
            couponsService.updateCoupons(e);
        });
    }
    //商城优惠卷超时
    public void mallCouponsMemberTimeout(){
        List<MallCouponsMember> list = mallCouponsMemberService.selectMallCouponsTimeout();
        list.forEach(e->{
            e.setCanUseState(DicConstants.SYS_N.getCode());
            mallCouponsMemberService.updateMallCouponsMember(e);
        });
    }

    public void mallCouponsTimeout(){
        List<MallCoupons> list = mallCouponsService.selectMallCouponsTimeout();
        list.forEach(e->{
            e.setFixedTimeState(DicConstants.SYS_N.getCode());
            mallCouponsService.updateMallCoupons(e);
        });
    }
}
